//
//  BGleadPicViewController.m
//  TingliFeng
//
//  Created by xinxuan on 16/1/4.
//  Copyright © 2016年 Bullgo. All rights reserved.
//

#import "BGleadPicViewController.h"
#import "TabBarViewController.h"
@interface BGleadPicViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView *LPScrollView;//引导图
@property (nonatomic, strong) NSArray *PicNameArray;//引导图数组
@end

@implementation BGleadPicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setLeadPicOnScrollView];
    [self.view addSubview:self.LPScrollView];
    self.LPScrollView.delegate = self;
    
    
}

#pragma mark ---- 私有方法
//添加引导图
-(void)setLeadPicOnScrollView{
    for (int i = 0; i < 4 ; i++) {
        NSString * nameString = [NSString stringWithFormat:@"0-1使用指导%d.jpg",i+1];
        UIImageView *leadPicView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * i, 0, self.view.frame.size.width, self.view.frame.size.height)];
        
        leadPicView.image = [UIImage imageNamed:nameString];
        
        [self.LPScrollView addSubview:leadPicView];
    }
    
    
}



#pragma mark ---- 懒加载
//引导图
-(UIScrollView *)LPScrollView{
    if (!_LPScrollView) {
        _LPScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
        _LPScrollView.contentSize = CGSizeMake(self.view.frame.size.width * self.PicNameArray.count, self.view.frame.size.height);
        self.LPScrollView.backgroundColor = [UIColor whiteColor];
        _LPScrollView.pagingEnabled = YES;//整屏翻
        _LPScrollView.bounces = NO;//不允许回弹
        _LPScrollView.showsHorizontalScrollIndicator = NO;//隐藏水平滚动条
    }
    return _LPScrollView;
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    if ((int)scrollView.contentOffset.x / self.view.frame.size.width == 3) {
        
        //添加轻扫手势
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer  alloc] initWithTarget:self action:@selector(tapGesture:)];
        //设置轻扫的方向
        //tapGesture.direction = UISwipeGestureRecognizerDirectionRight; //默认向右
        [self.view addGestureRecognizer:tapGesture];
        
    }
    
    
    
}

//点击手势触发方法
-(void)tapGesture:(UITapGestureRecognizer * )sender
{
    TabBarViewController * rootVC = [[TabBarViewController alloc] init];

    [self showDetailViewController:rootVC sender:self];
    //[self.navigationController pushViewController:[self tabbarController] animated:YES];
}


//引导图数组
-(NSArray *)PicNameArray{
    if (!_PicNameArray) {
        _PicNameArray = @[@"0-1使用指导1",@"0-1使用指导2", @"0-1使用指导3",@"0-1使用指导4"];
    }
    
    return _PicNameArray;
}




@end
